namespace ClassyBlog.Infrastructure
{
    using System;

    using DataAccess;
    using DomainObjects;

    public class CurrentBlogProvider : ICurrentBlogProvider
    {
        private Blog blog;

        public CurrentBlogProvider(IBlogRepository repository)
        {
            if (repository == null)
            {
                throw new ArgumentNullException("repository");
            }

            Repository = repository;
        }

        public virtual Blog Current
        {
            get
            {
                return blog ?? (blog = Repository.One());
            }
        }

        protected IBlogRepository Repository { get; private set; }
    }
}